<!--
 * @Author: 陈俊升 761723995@qq.com
 * @Date: 2023-12-12 11:14:35
 * @LastEditors: 陈俊升 761723995@qq.com
 * @LastEditTime: 2024-01-10 09:04:35
 * @FilePath: /hr_new_vue3/src/views/Management/Home/LeaveManagement/Certificate/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 工作台-实习管理-实习评价表格 -->
<template>
  <ConditionBox :margin-bottom="20">
    <template #left>
      <a-space>
        <div style="display: flex">
          <a-select :options="options" v-model="keyWold" />
          <a-input-search
            @press-enter="onSearch"
            @search="onSearch"
            v-model="keyWoldValue"
            placeholder="请输入"
          />
        </div>
        <a-input-search
          @press-enter="onSearch"
          @search="onSearch"
          v-model="phoneData"
          placeholder="输入手机号码搜索"
        />
        <a-button @click="reset">重置</a-button>
      </a-space>
    </template>
  </ConditionBox>
  <TableTurn :tableData="getTableData" ref="tableRef" :args="args">
    <a-table-column :width="80">
      <template #title> 序号 </template>
      <template #cell="{ rowIndex }">
        {{ rowIndex + 1 }}
      </template>
    </a-table-column>
    <a-table-column :width="150" title="实习评价名称" data-index="name">
    </a-table-column>
    <a-table-column :width="150" title="评价对象" data-index="userName">
    </a-table-column>
    <a-table-column :width="150" title="工号" data-index="handlerMatters">
    </a-table-column>
    <a-table-column :width="150" title="部门" data-index="handleStatus">
    </a-table-column>
    <a-table-column :width="150" title="职位" data-index="handleStatus">
    </a-table-column>
    <a-table-column
      :width="150"
      title="评价截止时间(天)"
      data-index="handleStatus"
    >
    </a-table-column>
    <a-table-column :width="150" title="操作" data-index="">
      <template #cell="{ record }">
        <a-button type="text" @click="handleClick(record)">
          {{ type === 1 ? '评分' : '查看详情' }}
        </a-button>
      </template>
    </a-table-column>
  </TableTurn>
</template>

<script lang="tsx" setup>
import { GetInternshipEvaluationScorerList } from '@/apis/management/human/humanChange/internship';
import { cloneDeep } from 'lodash';
import { Message, Modal } from '@arco-design/web-vue';

const props = withDefaults(
  defineProps<{
    type: 1 | 2; // 1 待评价 2已评价
  }>(),
  {}
);

const router = useRouter();

const id = 153; // 评分人id

// 模糊查询参数
const options = reactive([
  { label: '姓名', value: 'name' },
  { label: '职位', value: 'positionName' }
]);
// 模糊类型
const keyWold = ref('name');
// 模糊查询值
const keyWoldValue = ref('');

const phoneData = ref('');

let tableRef = ref();

const selectedListData = computed(() => tableRef.value.selectedListData);
const selectedList = computed(() => tableRef.value.selectedList);

// 选择器配置
const args = {
  rowSelection: {
    type: 'checkbox',
    showCheckedAll: true,
    onlyCurrent: false
  }
};

const getTableData = async (pageData?: any) => {
  try {
    let res = await GetInternshipEvaluationScorerList({
      // keyWold: keyWold.value,
      // keyWoldValue: keyWoldValue.value,
      // phoneData: phoneData.value,
      ...pageData,
      id,
      type: props.type
      // id: 153,
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};

const onSearch = () => {
  refresh();
};

const handleClick = (record: any) => {
  router.push({
    name: 'InternshipEvaluationDetail',
    query: {
      step: 4,
      userId: record.userId,
      isEdit: props.type === 1 ? 'true' : 'false'
    }
  });
};

// 重置数据
const reset = () => {
  keyWold.value = 'name';
  keyWoldValue.value = '';
  phoneData.value = '';
  refresh();
};

// 刷新列表
const refresh = (page?: any) => {
  tableRef.value.loadData(page);
};
</script>

<style lang="less" scoped></style>
